<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20" style="height:252px;">
                    <div class="user-info">
                      <div class="user-info-cont">
                        <div class="user-info-name">{{name}}</div>
                        <div>{{rolename}}</div>
                      </div>
                    </div>
                    <div>欢迎登录HR-SYSTEM系统</div>
                    <div class="role-div">愿您有个美好愉快的一天！</div>
                </el-card>
            </el-col>
            <el-col :span="16">
                <el-row :gutter="20" class="mgb20">
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-lx-people grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">{{ dataMap.nowMonther }}</div>
                                    <div>本月入场人数</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card shadow="hover">
                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover">
                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Schart from 'vue-schart';
import { selectDashboar} from '../../api/dashboard';
export default {
    name: 'dashboard',
    data() {
        return {
            name: localStorage.getItem('ms_username'),
            rolename: localStorage.getItem('ms_userrolenames'),
            dataMap:{},
            todoList: [
                {
                    title: '今天添加一个粉丝',
                    status: false
                },
                {
                    title: '今天添加一个粉丝',
                    status: false
                },
                {
                    title: '今天添加一个粉丝',
                    status: false
                },
                {
                    title: '今天添加一个粉丝',
                    status: false
                },
                {
                    title: '今天添加一个粉丝',
                    status: true
                },
                {
                    title: '今天添加一个粉丝',
                    status: true
                }
            ],
            data: [
                {
                    name: '2018/09/04',
                    value: 1083
                },
                {
                    name: '2018/09/05',
                    value: 941
                },
                {
                    name: '2018/09/06',
                    value: 1139
                },
                {
                    name: '2018/09/07',
                    value: 816
                },
                {
                    name: '2018/09/08',
                    value: 327
                },
                {
                    name: '2018/09/09',
                    value: 228
                },
                {
                    name: '2018/09/10',
                    value: 1065
                }
            ],
            options: {
                type: 'bar',
                title: {
                    text: '最近半年情况'
                },
                xRorate: 25,
                labels: [],
                datasets: [
                    {
                        label: '人数',
                        data: []
                    }
                ]
            },
            options2: {
                type: 'line',
                title: {
                    text: '各个月份观看情况'
                },
                labels: [],
                datasets: [
                    {
                        label: '人数',
                        data: []
                    }
                ]
            }
        };
    },
    components: {
        Schart
    },
    computed: {
        role() {
            return this.name === 'admin' ? '超级管理员' : '普通用户';
        }
    },
    created() {
      this.getData();
    },
    methods: {
        getData(){
          selectDashboar(this.query).then(res => {
            this.dataMap = res;
            if(res.halfYear){
              for (let key in res.halfYear) {
                this.options.labels.push(key);
                this.options.datasets[0].data.push(res.halfYear[key])
              }
            }
            if(res.oneYear){
              for (let key in res.oneYear) {
                this.options2.labels.push(key);
                this.options2.datasets[0].data.push(res.oneYear[key])
              }
            }

          });

        },
    }
};
</script>

<style scoped>

.role-div{
  font-size: 1.5vw;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-info-cont {
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.schart {
    width: 100%;
    height: 300px;
}
</style>